setwd("E:/5hmc_file/2_5hmc_yjp_bam/ASM/")
library(openxlsx)
filea=read.csv("20201112做汇总表/all.FDR.sig.at.least.one.add.direction.same.diff.csv",head=T)
filea$id=paste(filea$Chr,filea$Start,sep = ":")
filea1=filea[filea$FDR.sig>1,]
file=read.table("E:/5hmc_file/2_5hmc_yjp_bam/ASM/20210316LIBD.eQTL处理/53K.add.GWAS.eQTL.DEG.motif.for.analysis.txt",header=T,sep="\t")
#file$id=paste(file$Chr,file$Start,sep=":")
file=file[!duplicated(file$id),]	#对TF去重
file1=file[file$pattern.not.rm.dupl.num.DC>1,]
file2=file1[file1$BF_in_DC>1,]
file3=file1[file1$BF_in_DC>10,]

library(ggplot2)
library(RColorBrewer)
library(ggsci)

result=as.data.frame(table(file3$Func.refGene))
result$ratio=round(result$Freq/sum(result$Freq),4)
result=result[!result$ratio==0,]
result=result[order(result$Freq),]
result$lognum=log(result$ratio*1000)
result=result[result$lognum>0,]

p2=ggplot(result,aes(x=reorder(Var1,Freq), y=lognum, fill=Var1))+ geom_bar(stat="identity", color="black")+coord_polar()+theme_bw()+
  ylim(-5,12)+theme(
    panel.grid = element_blank(),
    panel.border= element_blank(),
    axis.text.y = element_blank(),
    axis.text.x = element_blank(),
    axis.ticks = element_blank(),
    axis.title = element_blank()
  )+geom_text(aes(label = paste(Var1,paste0(round(ratio,4)*100,"%"))),data = subset(result,Freq<median(result$Freq)),vjust = "left", hjust = "outward", color = "dark blue", fontface="bold")+
  geom_text(aes(label = paste0(Var1,"\n",paste0(round(ratio,4)*100,"%"))),data = subset(result,Freq>=median(result$Freq)),vjust = "left", hjust = "outward", color = "dark blue", fontface="bold")

p2+scale_fill_npg()+guides(fill=F) 

##保存在  E:\5hmc_file\2_5hmc_yjp_bam\ASM\20210318.位置信息统计图